<form action="106.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" name="sub" value="上传">
</form>
<?php
/**
 * User: lie
 * Date: 2020/12/4 11:31
 * Title: 合理定义上传文件名称
 * Description:
 * Error:
 */

if (!empty($_POST['sub'])) {
    if (!is_dir('./img')) {
        mkdir('./img');
    }
    if (!empty($_FILES['file']['name'])) {
        if ($_FILES['fiel']['error'] > 0) {
            echo "上传错误";
            switch ($_FILES['file']['error']) {
                case 1:
                    echo "上传文件大小超出配置文件规定值：";
                break;
                case 2:
                    echo "上传文件大小超出表单中的约定值：";
                break;
                case 3:
                    echo "上发文件不全：";
                break;
                case 1:
                    echo "没有上传文件：";
                break;
            }
        } else {
            $path = './img/'.rand().$_FILES['file']['name'];
            if (is_uploaded_file($_FILES['file']['tmp_name'])) {
                if (!move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
                    echo "上传失败";
                } else {
                    echo "文件".time().$_FILES['file']['name']."上传成功, 大小为：".$_FILES['file']['size'];
                }
            } else {
                echo "上传文件".$_FILES['file']['name']."不合法";
            }
        }
    }
}
